import java.util.concurrent.locks.ReentrantLock;

public class ReentractLockDemo {

	static int data = 0;
	static ReentrantLock lock = new ReentrantLock();
	
	public static void main(String[] args) {
		new Thread() {
            public void run() {
				for(int i = 0; i < 10; i++) {
				    try {
                        lock.lock();
                        ReentractLockDemo.data++;
                        System.out.println(ReentractLockDemo.data);
                        Thread.sleep(10000);
                        lock.unlock();
                    }catch (Exception e){
				        e.printStackTrace();
                    }

				}
			};

		}.start();

		new Thread() {
			public void run() {
			    while (true){
                    lock.lock();
                    ReentractLockDemo.data++;
                    System.out.println(ReentractLockDemo.data);
                    lock.unlock();
                }
			};

		}.start();

	}
	
}
